
use Data/Estimation_sample.dta, clear
	
	gen nexis_buildings  = ROOFME/PROOFME
		
		
	gen roofratio = ROOFME/ROOFTI
	gen roofratiobuildings = roofratio*nexis_buildings
		
	gen roofrelativeIV = (roofratio*nexis_buildings/[moduleprice])/1000


* 3 quarters is nine months 
local length = 3

	 
forval t = 0(1)`length' {
	gen event_after`t' =  SHCP_end ==`t' |  PFIT_starttime==`t' | PFIT_endtime==`t' | ///
	 SRES1_end ==`t' | SRES2_end==`t' | SRES_TFIT_endtime==`t' | FFIT_endtime==`t'
	 
	 
	 gen event_before`t' =  SHCP_end ==-`t'  | PFIT_starttime==-`t' | PFIT_endtime==-`t' | ///
	 SRES1_end ==-`t' | SRES2_end==-`t' | SRES_TFIT_endtime==-`t' | FFIT_endtime==-`t'
	
	gen event_after_high`t' = event_after`t'*roofrelativeIV
	gen event_before_high`t' = event_before`t'*roofrelativeIV
	
	drop event_after`t'
	drop event_before`t'
	
	
	
	
	}

	
		
	
drop event_after_high0 // event_before_high1 

label variable event_before_high3  "Event period -3"
label variable event_before_high2  "Event period -2"
label variable event_before_high0  "Event period "
label variable event_after_high1   "Event period +1"
label variable event_after_high2   "Event period +2"
label variable event_after_high3   "Event period +3"


xi: xtivreg2 green_p event_*  i.quarter  [aweight =NCustomer	] , fe cluster(postcode)

 outreg2 using Analysis/Motivation_RF, bdec(2) se  nocons label ctitle()  ///
	keep(event* cumin mean_weighted TotalHouse_interp  median_incom quarter ) addtext(Postcode FE, Yes) tex(fragment pretty) nonotes replace


eststo model2a 

coefplot (model2a, keep(event_before_high3  event_before_high2  event_before_high1) mcolor(blue)  ciopts(lcolor(blue)) msymbol(o)) ///
  (model2a, keep(event_before_high0 ) mcolor(gs0) ciopts(lcolor(gso)) msymbol(o)) ///
  (model2a, keep( event_after_high1 event_after_high2 event_after_high3 ) mcolor(red)  ciopts(lcolor(red)) msymbol(o)), vertical ///
relocate(event_before_high3 = -2.84 event_before_high2 = -1.84 event_before_high1 = -0.84 event_before_high0 = 0 ///
event_after_high1 =0.84  event_after_high2=1.84 event_after_high3=2.84 ) xlabel(-3(1)3)  legend(off) yline(0) xline(0, lcolor(gs10) lpattern(dash) lwidth(vthin)) ///
xtitle("Event time") 
graph export Analysis/RF_motivation.png, replace







